<?php


namespace api\app\controller;



use api\app\model\NewsModel;
use cmf\controller\RestBaseController;
use think\facade\Db;

class NewsController extends RestBaseController
{
    public function index()
    {
        $list = NewsModel::select();
        $this->success('公告显示', $list);
    }

    public function getNewsList()
    {
        $keyword = input('keyword', 2);
        $where = [];
        if ($keyword) {
            $where[] = ['title|author', 'like', "%$keyword"];
        }
        $page = input('page/d', 1);
        $pgaeSize = input('page_size/d', 10);
        $list = NewsModel::order('list_order', 'desc')
            ->field('id,title,image,create_time,abstract')
            ->where($where)
            ->page($page, $pgaeSize)
            ->select();
        $this->success('公告列表', $list);
    }

    public function getNewsInfo()
    {
        $id = input('id/d');
        if (empty($id)) {
            $this->error('参数错误');
        }
        $news = NewsModel::withoutField('delete_time,list_order')->find($id);
        if (!$news) {
            $this->error('公告不存在');
        }
        $content1 = htmlspecialchars_decode($news['content']);
        $content2 = cmf_replace_content_file_url($content1, true);
        $this->success('返回成功', $news);
    }
}
